package www.bwsensing.com.common.netty.handler;

import www.bwsensing.com.common.client.PushKindEnum;
import www.bwsensing.com.common.utills.NetworkInterfaceUtil;
import www.bwsensing.com.common.utills.UuidUtils;
import www.bwsensing.com.service.collection.database.dataobject.ServiceData;
import www.bwsensing.com.stream.DataStreamReceive;
import www.bwsensing.com.stream.object.DataMessage;

import java.util.Date;
import java.util.List;

/**
 * @author macos-zyj
 */
public interface DataPushHandle {

    /**
     * 获取推送消息体
     * @param dataMessages
     * @param receiveMethod
     * @param serviceData
     * @return
     */
    default DataStreamReceive getDataStreamPush(List<DataMessage> dataMessages,String receiveMethod,ServiceData serviceData){
        Date receiveTime = new Date();
        String senderAddress = NetworkInterfaceUtil.getHostIp();
        String hostname = NetworkInterfaceUtil.getHostName();
        DataStreamReceive receiveData = new DataStreamReceive(PushKindEnum.MQTT.getMessageKind());
        receiveData.setTransactionId(UuidUtils.generateShortUuid());
        receiveData.setNeedIdempotent(true);
        receiveData.setReceiveData(dataMessages);
        receiveData.setReceiveMethod(receiveMethod);
        receiveData.setUniqueCode(serviceData.getServiceValue());
        receiveData.setReceiveTime(receiveTime);
        receiveData.setModelId(serviceData.getId());
        receiveData.setSender(senderAddress);
        receiveData.setHostName(hostname);
        return receiveData;
    }
}
